package com.zhijiang.hospital.service.impl;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhijiang.hospital.entity.OutpatientPerformanceEvaluation;
import com.zhijiang.hospital.entity.dto.OutpatientPerformanceEvaluationDto;
import com.zhijiang.hospital.mapper.OutpatientPerformanceEvaluationMapper;
import com.zhijiang.hospital.service.OutpatientPerformanceEvaluationService;
import com.zhijiang.util.BaseQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 75936
 * @version 1.0
 * @project zhijiang_hospital_data
 * @description
 * @date 2022-10-26 10:37:11
 */
@Service
public class OutpatientPerformanceEvaluationServiceImpl implements OutpatientPerformanceEvaluationService {
    @Autowired
    private OutpatientPerformanceEvaluationMapper outpatientPerformanceEvaluationMapper;

    @Override
    public List<OutpatientPerformanceEvaluationDto> findAll() {
        return outpatientPerformanceEvaluationMapper.findAll();
    }

    @Override
    public Page<OutpatientPerformanceEvaluation> loadPageList(BaseQuery baseQuery) {
        QueryWrapper<OutpatientPerformanceEvaluation> outpatientPerformanceEvaluationQueryWrapper = new QueryWrapper<>();
        outpatientPerformanceEvaluationQueryWrapper.
                apply(StrUtil.isNotBlank(baseQuery.getStartTime()),
                        "create_time >= to_date('" + baseQuery.getStartTime() + "','yyyy-mm-dd hh24:mi:ss')").
                apply(StrUtil.isNotBlank(baseQuery.getEndTime()),
                        "create_time <= to_date('" + baseQuery.getEndTime() + "','yyyy-mm-dd hh24:mi:ss')").
                eq(StringUtils.isNotBlank(baseQuery.getDepartment()) && !baseQuery.getDepartment().equals("全部科室"), "dept_Name", baseQuery.getDepartment());
        return outpatientPerformanceEvaluationMapper.selectPage(new Page<>(baseQuery.getPage(), baseQuery.getPageSize()), outpatientPerformanceEvaluationQueryWrapper);
    }

    @Override
    public OutpatientPerformanceEvaluation loadOne(String id) {
        return outpatientPerformanceEvaluationMapper.selectById(id);
    }

    @Override
    public List<OutpatientPerformanceEvaluation> loadDept() {
        List list = outpatientPerformanceEvaluationMapper.selectList(null).stream().map(OutpatientPerformanceEvaluation::getDeptName).distinct().collect(Collectors.toList());
        return list;
    }

    @Override
    public List<OutpatientPerformanceEvaluation> outpatientPerformanceEvaluation() {
        List<OutpatientPerformanceEvaluation> list = outpatientPerformanceEvaluationMapper.
                selectList(null).stream().
                filter(outpatientPerformanceEvaluation
                        -> outpatientPerformanceEvaluation.getEmployeeCode().
                        equals("007")).collect(Collectors.toList());
        return list;
    }
}
